home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Found / BCCollec / Structs / Stacks / BCStac.h < prev    next >
Encoding:
Text File  |  1994-04-21  |  2.0 KB  |  105 lines  |  [TEXT/MPS ]

  1. //  The C++ Booch Components (Version 2.1)
  2. //  (C) Copyright 1990-1993 Grady Booch. All Rights Reserved..
  3. //
  4. //  BCStac.h
  5. //
  6. //  This file contains the declaration of the stack abstract base class
  7. //  and its iterators.
  8.  
  9. #ifndef BCSTAC_H
  10. #define BCSTAC_H 1
  11.  
  12. #include "BCType.h"
  13.  
  14. template<class Item>
  15. class BC_TStackActiveIterator;
  16.  
  17. template<class Item>
  18. class BC_TStackPassiveIterator;
  19.  
  20. template<class Item, class Structure>
  21. class BC_TPersist;
  22.  
  23. // Stack abstact base class
  24.  
  25. template<class Item>
  26. class BC_TStack {
  27. public:
  28.  
  29.   BC_TStack();
  30.   BC_TStack(const BC_TStack<Item>&);
  31.   virtual ~BC_TStack();
  32.   
  33.   virtual BC_TStack<Item>& operator=(const BC_TStack<Item>&);
  34.   virtual BC_Boolean operator==(const BC_TStack<Item>&) const;
  35.   BC_Boolean operator!=(const BC_TStack<Item>&) const;
  36.  
  37.   virtual void Clear() = 0;
  38.   virtual void Push(const Item&) = 0;
  39.   virtual void Pop() = 0;
  40.   
  41.   virtual BC_Index Depth() const = 0;
  42.   virtual BC_Boolean IsEmpty() const = 0;
  43.   virtual const Item& Top() const = 0;
  44.   virtual Item& Top() = 0;
  45.   
  46. protected:
  47.  
  48.   virtual void Purge() = 0;
  49.   virtual void Add(const Item&) = 0;
  50.   virtual BC_Index Cardinality() const = 0;
  51.   virtual const Item& ItemAt(BC_Index) const = 0;
  52.   
  53.   virtual void Lock();
  54.   virtual void Unlock();
  55.   
  56. private:
  57.  
  58.   friend class BC_TStackActiveIterator<Item>;
  59.   friend class BC_TStackPassiveIterator<Item>;
  60.  
  61.   friend class BC_TPersist<Item, BC_TStack<Item> >;
  62.  
  63. };
  64.  
  65. // Stack iterators
  66.  
  67. template <class Item>
  68. class BC_TStackActiveIterator {
  69. public:
  70.  
  71.   BC_TStackActiveIterator(const BC_TStack<Item>&); 
  72.   ~BC_TStackActiveIterator();
  73.   
  74.   void Reset();
  75.   BC_Boolean Next();
  76.  
  77.   BC_Boolean IsDone() const;
  78.   const Item* CurrentItem() const;
  79.   Item* CurrentItem();
  80.   
  81. protected:
  82.  
  83.   const BC_TStack<Item>& fStack;
  84.   BC_ExtendedIndex fIndex;
  85.   
  86. };
  87.  
  88. template <class Item>
  89. class BC_TStackPassiveIterator {
  90. public:
  91.  
  92.   BC_TStackPassiveIterator(const BC_TStack<Item>&);
  93.   ~BC_TStackPassiveIterator();
  94.   
  95.   BC_Boolean Apply(BC_Boolean (*)(const Item&));
  96.   BC_Boolean Apply(BC_Boolean (*)(Item&));
  97.   
  98. protected:
  99.  
  100.   const BC_TStack<Item>& fStack;
  101.  
  102. };
  103.  
  104. #endif
  105.